package com.zxn.kotlin.generic

import java.lang.reflect.Field
import java.lang.reflect.Method

open class BaseClass {
    companion object {
        val value = 10
    }
}

class ChildClass : BaseClass() {

    companion object {

        val value = 15

        fun printNumber() {
            println(value)
        }
    }
}

inline fun <reified T : BaseClass> getValue(): Int {
    //return T::class.java.getDeclaredField("value").get(null) as Int
    val field: Field = T::class.java.getDeclaredField("value")
    field.isAccessible = true
    return field.get(null) as Int
}

inline fun <reified T : BaseClass> printValue() {
    println(T::class.java.kotlin.simpleName)
    val method: Method = T::class.java.getDeclaredMethod("printNumber()")
    println(method.defaultValue)
    //field.isAccessible = true
    //return field.get(null) as Int
}

inline fun <reified T> printMethod(content: String) {
    val method: Method = T::class.java.getMethod("bind", String::class.java)
    method.invoke(null, content)
    //println(method.defaultValue)
    //field.isAccessible = true
    //return field.get(null) as Int
}

fun main() {
    //println(getValue<BaseClass>())
    //println(getValue<ChildClass>())
    //printValue<ChildClass>()
    printMethod<Utils>("zxn721688")
}
